package main

import (
	"fmt"
	"github.com/julienschmidt/httprouter"
	"net/http"
)

//https://codegangsta.gitbooks.io/building-web-apps-with-go/content/url_routing/index.html
func main() {
	r := httprouter.New()
	r.GET("/", HomeRouter)
	r.GET("/posts", PostsIndexHandler)
	r.POST("/posts", PostsCreatedHandler)
	r.GET("/posts/:id", PostShowHandler)
	r.PUT("/posts/:id", PostUpdateHandler)
	r.GET("/posts/:id/edit", PostEditHandler)

	fmt.Println("starting server on 8080")
	http.ListenAndServe(":8080", r)
}

func HomeRouter(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	fmt.Fprintln(rw, "Home")
}
func PostsIndexHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	fmt.Fprintln(rw, "posts index")
}
func PostsCreatedHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	fmt.Fprintln(rw, "posts create")
}
func PostShowHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	id := p.ByName("id")
	fmt.Fprintf(rw, "showing post", id)
}
func PostUpdateHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	fmt.Fprintln(rw, "posts updated")
}
func PostEditHandler(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	fmt.Fprintln(rw, "posts edit")
}
